import * as QuarkGIS from "quarkgis"
import "quarkgis/Source/Widgets/widgets.css"
import PerformanceWatchdog from "quarkgis/Source/Widgets/PerformanceWatchdog/PerformanceWatchdog";
import QuarkGIS3DTilesInspector from "quarkgis/Source/Widgets/QuarkGIS3DTilesInspector/QuarkGIS3DTilesInspector";
// // Load QuarkGIS World Terrain
QuarkGIS.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJhNDkzMjk5Mi1mYmZjLTQ4ODQtOTdkOC1iYzBjMTQ4OWZjNDYiLCJpZCI6Njk2NTcsImlhdCI6MTYzMzY1ODA1OX0.2YakiQD47f85BIWE5z_3ULLrPsdjE97JlaAj8z8oEEA'

// 仅保存西太
var providerViewModels = [];
var theatyMap = new QuarkGIS.UrlTemplateImageryProvider({
	url: 'http://47.93.32.68/map_tile/{z}/{x}/{y}.jpg'
})

var theatyMapModel = new QuarkGIS.ProviderViewModel({
	name: '西太GIS',
	iconUrl: QuarkGIS.buildModuleUrl('./Widgets/Images/ImageryProviders/gaode_img.png'),
	tooltip: '地图服务',
	creationFunction: function () {
		return theatyMap;
	}
});
providerViewModels.push(theatyMapModel);

// http://47.93.32.68:8080/geoserver/diankeyuan_jianmo/wms?service=WMS&version=1.1.0&request=GetMap&layers=diankeyuan_jianmo:china_jianmo&styles=&bbox=-180.0,-90.0,180.0,90.0&width=768&height=384&srs=EPSG:4326&format=application/openlayers
export function creatCommonViewer(divContainer = 'quarkgisContainer') {
	var viewer = new QuarkGIS.Viewer(divContainer, {
		// imageryProviderViewModels: providerViewModels,//可供BaseLayerPicker选择的图像图层ProviderViewModel数组
		imageryProvider: new QuarkGIS.WebMapServiceImageryProvider({
			url: 'http://121.41.36.51:7080/geoserver/xabd/wms',
			layers: 'xabd:xabd_layer_group',
			parameters: {
				service: 'WMS',
				format: 'image/png',
				transparent: true
			},
			enablePickFeatures: false
		}),
		selectionIndicator: false,//设置绿色框框不可见
		projectionPicker: false,//显示投影方式 正交和透射
		vrButton: false,// 右下角vr按钮
		shouldAnimate: false,
		sceneModePicker: false,// 隐藏2d，2.5d，3d切换
		navigationHelpButton: false,//隐藏帮助
		sceneMode: QuarkGIS.SceneMode.SCENE2D,//默认是3d模式 SCENE2D
		geocoder: false,
		homeButton: false, // 隐藏home主页
		fullscreenButton: false,// 隐藏全屏按钮
		animation: false,//隐藏调整动画
		timeline: false,//隐藏时间轴
		baseLayerPicker: false,// 图层选择空间
		mapMode2D: QuarkGIS.MapMode2D.ROTATE,
		// terrainProvider: QuarkGIS.EllipsoidTerrainProvider(), //控制图层中的地形地形TerrainProvider 显示与移除 EllipsoidTerrainProvider-> 无地形 createWorldTerrain->有地形
	})
	viewer.scene.debugShowFramesPerSecond = false;//展示帧率
	viewer.scene.screenSpaceCameraController.inertiaTranslate = false   // 取消平移惯性
	viewer.scene.screenSpaceCameraController.inertiaZoom = false  // 取消缩放惯性
	viewer.scene.screenSpaceCameraController.inertiaSpin = false  // 取消旋转惯性
	// viewer.extend(QuarkGIS.viewerQuarkGIS3DTilesInspectorMixin);//3D tiles 面板
	// viewer.extend(QuarkGIS.viewerQuarkGISInspectorMixin);

	// viewer.animation.container.style.display ='none';//隐藏动画控件
	// viewer.timeline.container.style.display ='none';//隐藏时间线控件

	var longitude = Number(process.env.VUE_APP_HOME_LONGITUDE);
	var latitude = Number(process.env.VUE_APP_HOME_LATITUDE);
	var height = Number(process.env.VUE_APP_HOME_HEIGHT);
	viewer.camera.flyTo({
		destination: QuarkGIS.Cartesian3.fromDegrees(longitude, latitude, height), //摄像机的最终位置
		duration: 1,  //飞行所用时间
		orientation: {
			heading: QuarkGIS.Math.toRadians(process.env.VUE_APP_ROTATION_ANGLE, 0),
		},
	});
	// 设置中心点为中国 e

	viewer._quarkgisWidget._creditContainer.style.display = "none";

	return viewer;
}
